package com.cyf.service.impl;

import com.cyf.db.bean.InParking;
import com.cyf.db.bean.OnlinePayUser;
import com.cyf.db.mapper.OnlinePayUserMapper;
import com.cyf.service.CommonService;
import com.cyf.service.bean.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 公共接口
 * Created by hfy on 2017/4/28.
 */
@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private OnlinePayUserMapper onlinePayUserMapper;

    @Override
    public void checkSupportOnlinePay(InParking inParking) throws CustomException {
        // 车场未激活在线支付，不能获取费用
        boolean supportOnlinePay = checkSupportOnlinePay(inParking.getParkingId());
        if (!supportOnlinePay) {
            throw new CustomException("车场暂不支持网络支付！");
        }

        if (inParking.getLockStatus() != null && inParking.getLockStatus() == InParking.LOCK) {
            throw new CustomException("车辆已锁定！");
        }
    }

    @Override
    public boolean checkSupportOnlinePay(int parkingId) {
        OnlinePayUser onlinePayUser = onlinePayUserMapper.getByParkingId(parkingId);
        return !(onlinePayUser == null || onlinePayUser.getStatus() == OnlinePayUser.REVIEW_FAIL);
    }
}
